#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int judge(char* p)
{
	int a, b, c;
	int cnt = 0;
	while (*p == 'A')
	{
		cnt++;
		p++;
	}
	a = cnt;
	cnt = 0;
	if (*p != 'P')
	{
		return 0;
	}
	p++;
	if (*p != 'A')
	{
		return 0;
	}
	while (*p == 'A')
	{
		cnt++;
		p++;
	}
	b = cnt;
	cnt = 0;
	if (*p != 'T')
	{
		return 0;
	}
	p++;
	while (*p == 'A')
	{
		cnt++;
		p++;
	}
	c = cnt;
	cnt = 0;
	if (a * b != c)
	{
		return 0;
	}
	else
	{
		return 1;
	}

}
int main()
{
	int str[10];
	int x = 0;
	int i = 0;
	scanf("%d", &x);
	for (i= 0; i < x; i++)
	{
		char arr[101];
		scanf("%s", arr);
		str[i] = judge(arr);
	}
	for (int a = 0; a < x; a++)
	{
		if (str[a])
		{
			printf("%s", "YES\n");
		}
		else
		{
			printf("%s", "NO\n");
		}
	}
	
	return 0;
}
